package fi.kela.se.epsos.data.model;

import java.util.Date;

import org.w3c.dom.Document;

import tr.com.srdc.epsos.util.Constants;

import fi.kela.se.epsos.data.model.SearchCriteria.Criteria;
/**
 * Factory for fi.kela.se.epsos.data.model interfaces.
 * 
 * @author mimyllyv
 *
 */
public class DocumentFactory {
	
	public static SearchCriteria createSearchCriteria() {
		return new SearchCriteriaImpl();
	}

	public static SearchCriteria createSearchCriteria(Criteria c, String value) {
		SearchCriteria sc = new SearchCriteriaImpl();
		sc.add(c, value);
		return sc;
	}

	public static <T extends EPSOSDocumentMetaData> DocumentAssociation<T> createDocumentAssociation(T xml, T pdf) {
		return new DocumentAssociationImpl<T>(xml, pdf);
	}

	public static EPSOSDocument createEPSOSDocument(String patientId, String classCode, Document document) {
		return new EPSOSDocumentImpl(patientId, classCode, document);
	}
	
	private static EPDocumentMetaData createEPDocument(int documentFormat, String id, String patientId, 
			Date effectiveDate, String repositoryId, String title, String author) {
		EPSOSDocumentMetaData metaData = new EPSOSDocumentMetaDataImpl(id, patientId, documentFormat, effectiveDate, Constants.EP_CLASSCODE, repositoryId, title, author);
		return new EPDocumentMetaDataImpl(metaData);
	}

	public static EPDocumentMetaData createEPDocumentPDF(String id, String patientId, Date effectiveDate, 
			String repositoryId, String title, String author) {
		return createEPDocument(2, id, patientId, effectiveDate, repositoryId, title, author);
	}

	public static EPDocumentMetaData createEPDocumentXML(String id, String patientId, Date effectiveDate, 
			String repositoryId, String title, String author) {
		return createEPDocument(1, id, patientId, effectiveDate, repositoryId, title, author);
	}
	
	private static PSDocumentMetaData createPSDocument(int documentFormat, String id, String patientId, 
			Date effectiveDate, String repositoryId, String title, String author) {
		
		EPSOSDocumentMetaData metaData = new EPSOSDocumentMetaDataImpl(id, patientId, documentFormat, effectiveDate, Constants.PS_CLASSCODE, repositoryId, title, author);
		return new PSDocumentMetaDataImpl(metaData);
	}

	public static PSDocumentMetaData createPSDocumentPDF(String id, String patientId, Date effectiveDate, String repositoryId, String title, String author) {
		return createPSDocument(2, id, patientId, effectiveDate, repositoryId, title, author);
	}

	public static PSDocumentMetaData createPSDocumentXML(String id, String patientId, Date effectiveDate, String repositoryId, String title, String author) {
		return createPSDocument(1, id, patientId, effectiveDate, repositoryId, title, author);
	}
}
